package com.example.yls.demoa;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    private ArrayList<Student> studentArrayList = new ArrayList<>();
    private RecyclerView rlvy_stu;
    private StuAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initStuArray();

        adapter = new StuAdapter(MainActivity.this,studentArrayList);

        rlvy_stu = findViewById(R.id.rlve_stu);

        rlvy_stu.setAdapter(adapter);

        LinearLayoutManager manager = new LinearLayoutManager(MainActivity.this);
        rlvy_stu.setLayoutManager(manager);


    }

    /**
     * 初始化学生列表
     */
    private void initStuArray() {
        Student s1 = new Student("10010","陈一",12,R.drawable.dog1);
        Student s2 = new Student("10011","陈二",13,R.drawable.dog2);
        Student s3 = new Student("10012","陈三",14,R.drawable.dog3);
        Student s4 = new Student("10013","陈四",15,R.drawable.dog4);
        Student s5 = new Student("10014","陈五",16,R.drawable.dog5);
        studentArrayList.add(s1);
        studentArrayList.add(s2);
        studentArrayList.add(s3);
        studentArrayList.add(s4);
        studentArrayList.add(s5);


    }
}
